const { http } = require("../../request/http");

Page({
  data:{
    tabs: [{
      id: 0,
      value: "全部",
      isActive: true
    },
    {
      id: 1,
      value: "待付款",
      isActive: false
    },
    {
      id: 2,
      value: "待发货",
      isActive: false
    },
    {
      id: 3,
      value: "退货/退款",
      isActive: false
    }
  ],
  },
  onShow(options){
    let pages = getCurrentPages();
    // 数组中最大的索引就是当前页面
    let currentPage = pages[pages.length-1];
    // 获取url上的type参数
    const {type} = currentPage.options
    this.changeTitleByIndex(type-1)
    
  },
  // 获取订单列表
  async getOrders(type){
    const res = await http({url:"/my/orders/all",data:{type},Authorization:wx.getStorageSync('token')})
  },
  // 根据标题索引来激活选中 标题数组
  changeTitleByIndex(index){
    let {
      tabs
    } = this.data
    tabs.forEach((v, i) => i === index ? v.isActive = true : v.isActive = false)
    this.setData({
      tabs
    })
  },
    // 从子组件传递标题点击事件
    handelfatherTap(e) {
      // console.log();
      let index = e.detail
      this.changeTitleByIndex(index);
      this.getOrders(index+1)
    },
})